import { getAreaObj, regularRule } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '所属机构',
			prop: 'creditCode',
			propName: 'organizationName',
			type: 'remoteSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'creditCode',
			filterLabel: 'organizationName',
			multiple: false,
			rules: [{ required: true, message: '请输入当前所属机构' }],
			span: 24,
			change: (item, form, value) => {
				if (!item.creditCode) {
					return
				}
				form.organizationId = item.creditCode
			},
		},
		{
			type: 'DividerHtml',
			modelValue: '出入人信息',
			prop: 'contactHtml',
			labelPosition: 'top',
			position: 'center',
			span: 24,
		},
		{
			label: '姓名',
			prop: 'personName',
			type: 'input',
			maxlength: '100',
			showWordLimit: true,
			span: 8,
			rules: [{ required: true, message: '请输入姓名' }],
		},
		{
			label: '联系方式',
			prop: 'phone',
			type: 'input',
			span: 8,
			changeField: true,
			rules: [
				{ required: true, message: '请输入联系方式' },
				{ pattern: regularRule.phone, message: '请输入正确的联系电话' },
			],
		},
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'input',
			span: 8,
			changeField: true,
			rules: [{ required: true, message: '请输入证件号码' }],
		},
		{
			label: '体温',
			prop: 'temperature',
			type: 'input',
			span: 8,
			rules: [{ required: true, message: '请输入体温' }],
		},
		{
			label: '车牌号',
			prop: 'carNumber',
			type: 'input',
			span: 8,
		},
		{
			label: '出入类型',
			prop: 'type',
			type: 'select',
			dicData: [
				{ label: '家属探视', value: 1},
				{ label: '老人接送', value: 2 },
				{ label: '外来办事', value: 3 },
			],
			span: 8,
			rules: [{ required: true, message: '请选择出入类型' }],
		},
		{
			label: '现居地区',
			prop: 'areas',
			propName: 'nowAddress',
			type: 'AplidAreaSelect',
			changeField: true,
			rules: [{ required: true, message: '请选择现居地区' }],
			span: 24,
		},

		{
			label: '签字照片',
			tip: '',
			prop: 'signaturePic',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '出入时间', prop: 'createTime' },
		{ label: '姓名', prop: 'personName' },
		{ label: '联系方式', prop: 'phone' },
		{
			label: '体温',
			prop: 'temperature',
		},
		{
			label: '出入类型',
			prop: 'type',
			custome: 'tag',
			dicData: [
				{ label: '家属探视', value: '1' },
				{ label: '老人接送', value: '2' },
				{ label: '外来办事', value: '3' },
			],
		},
		{ label: '签字照片', prop: 'signaturePic', custome: 'file' },
		
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_pbMemberAssess_page',
}
export const baseConfig = {
	pageName: '出入院扫码登记记录',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'personName',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	formConfig,
	tableConfig,
	detailConfig: formConfig,

	operateFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form, '', 'get')
			resolve({
				...form,
				...areaObj,
				areas: areaObj.areaIds,
			})
		})
	},

	saveFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form.areas)
			resolve({
				...form,
				...areaObj,
				areas: undefined,
			})
		})
	},
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
}
